home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 133 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  61 lines

  1. Path: news.production.compuserve.com!news
  2. From: Dave Hand <70621.3624@CompuServe.COM>
  3. Newsgroups: comp.lang.c,comp.lang.c++
  4. Subject: Poor floating point code in BC++
  5. Date: 2 Jan 1996 00:00:42 GMT
  6. Organization: Singular Software, Inc.
  7. Message-ID: <4c9sja$gke$1@mhafc.production.compuserve.com>
  8.  
  9. BC++ 4.51 seems to generate very poor floating point code. I would be
  10. interested to know how well other compilers do on the following
  11. examples. These were compiled using options: i486 CPU, fast floating
  12. point, optimize for speed, large memory model.
  13.  
  14. main()
  15.     {
  16.     double x,y,z;
  17.     int n;
  18.  
  19.     x = 4.5;
  20.     y = 10.7;
  21.     n = x;
  22.     z = x * y;
  23.     }
  24.  
  25. Plain arithmetic, such as z = x * y, is generated inline as one would
  26. expect. You would think the line n = x would be quite fast. However,
  27. it generates a function call:
  28.  
  29. n=x;
  30.     wait
  31.     fld qword ptr[bp-0A]
  32.     call far FTOL@
  33.     mov [bp-02],ax
  34.  
  35. where FTOL@ is a very long function for what is does:
  36.  
  37.     push bp
  38.     mov bp,sp
  39.     sub sp,000A
  40.     fnstcw word ptr[bp-02]
  41.     fwait
  42.     mov al,[bp-01]
  43.     or byte ptr[bp-01],0C
  44.     fldcw word ptr[bp-02]
  45.     fistp qword ptr [bp-0A]  <<-- here is the meat of it.
  46.     mov [bp-01],al
  47.     fldcw word ptr[bp-02]
  48.     mov ax,[bp-0A]
  49.     mov dx,[bp-08]
  50.     mov sp,bp
  51.     pop bp
  52.     retf
  53.  
  54. I was trying to optimize some graphics code. The net result is that
  55. in many graphics calculations, the final conversion from world
  56. coordinates to screen coordinates is the overwhelming majority of the
  57. time. There are many other places where BC++ seems to generate very
  58. bad floating point code (unless I'm missing some important point). I
  59. would very much like to know if other compilers do a better job (or
  60. set me straight as to why the above code makes sense).   
  61.